import bs4
from loguru import logger
from settings import LOG_LEVEL, LOG_FILE_PATH, LOG_ROTATION
import os
from selenium.webdriver.chrome.options import Options
import re
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.ui import Select

logger.add(LOG_FILE_PATH, level=LOG_LEVEL, rotation=LOG_ROTATION, encoding="utf-8")


@logger.catch
def log_catch_test(a, b):
    c = a / b
    d = log_catch_test_inner(c, 0)
    return d


def log_catch_test_inner(a, b):
    c = a / b
    return c


if __name__ == '__main__':
    # with open(r'D:\Code\Python_code\LryAssistant\temp\测试1--MIPS32机器指令格式及编码：答题回顾.html', 'r', encoding="utf-8") as f:
    #     soup = bs4.BeautifulSoup(f.read(), "lxml")
    # lis = soup.find_all(name="p", dir="ltr")
    # for p in lis:
    #     print(p.text)
    # aaa = {}
    # aaa["  "] = 3
    # print(aaa.keys())
    # logger.info("hello")
    # log_catch_test(3, 2)
    # print(os.path.dirname(os.path.abspath(__file__)))
    print(os.listdir(r"D:\Code\Python_code\LryAssistant\temp"))
    options = Options()
    # 去掉自动化测试的提示
    options.add_experimental_option('useAutomationExtension', False)
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 取消保存密码提示框
    prefs = {"credentials_enable_service": False,
             "profile.password_manager_enabled": False
             }
    options.add_experimental_option("prefs", prefs)
    # 获取driver对象
    driver = webdriver.Chrome(options)
    time.sleep(3)
    driver.close()
